home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Libraries / VideoToolbox 94.11.17 / VideoToolboxSources / ChooseScreen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-17  |  2.0 KB  |  73 lines  |  [TEXT/KAHL]

  1. /*
  2. ChooseScreen.c
  3.  
  4. Displays a screen number on every screen, and accepts the typed selection from
  5. the user, using the argument value as the default. No check is made for
  6. validity of the default or the reply.
  7.     screen=1;
  8.     screen=ChooseScreen(screen,"Which screen?");
  9.  
  10. HISTORY:
  11. 9/5/94 dgp removed assumption in printf's that int==short.
  12. 10/2/94 dgp added question argument.
  13. */
  14. #include "VideoToolbox.h"
  15. #if UNIVERSAL_HEADERS
  16.     #include <LowMem.h>
  17. #else
  18.     extern void LMSetGhostWindow(WindowPeek GhostWindowValue);
  19.     #define LMSetGhostWindow(GhostWindowValue) ((* (WindowPeek *) 0x0A84) = (GhostWindowValue))
  20. #endif
  21.  
  22. int ChooseScreen(int screen,const char *question)
  23. {
  24.     short i,fontNumber,textSize;
  25.     Rect r;
  26.     GDHandle device=NULL,oldDevice=NULL;
  27.     WindowPtr window=NULL,oldWindow=NULL,windows[MAX_SCREENS];
  28.     unsigned char string[16]="\p0";
  29.     char str[32];
  30.     FontInfo fontInfo;
  31.     long ticks;
  32.  
  33.     oldDevice=GetGDevice();
  34.     SetGDevice(GetMainDevice());
  35.     GetPort(&oldWindow);
  36.     ticks=TickCount();
  37.     for(i=0;i<MAX_SCREENS;i++){
  38.         device=GetScreenDevice(i);
  39.         if(device == NULL)break;
  40.         SetRect(&r,0,0,160,160);
  41.         CenterRectInRect(&r,&(*device)->gdRect);
  42.         string[1]='0'+i;
  43.         windows[i]=NewWindow(NULL,&r,string,TRUE,plainDBox,(WindowPtr) -1L,0,0);
  44.         SetPort(windows[i]);
  45.         if(i==0)GetFNum("\pChicago",&fontNumber);
  46.         TextFont(fontNumber);
  47.         textSize=128;
  48.         TextSize(textSize);
  49.         if(i==0)GetFontInfo(&fontInfo);
  50.         SetRect(&r,0,0,StringWidth(string),fontInfo.ascent);
  51.         CenterRectInRect(&r,&windows[i]->portRect);
  52.         MoveTo(r.left,r.bottom);
  53.         DrawString(string);
  54.     }
  55.     LMSetGhostWindow((WindowPeek)windows[0]);    // doesn't work; don't know why.
  56.     SetPort(oldWindow);
  57.     SetGDevice(oldDevice);
  58.     ticks=ticks+50-TickCount();
  59.     if(ticks>0)Delay(ticks,&ticks);
  60.     printf("%s (%d):",question,screen);
  61.     #if __MWERKS__
  62.         SelectWindow(oldWindow);    // bring console forward. Needed by CodeWarrior; crashes THINK C
  63.     #endif
  64.     gets(str);
  65.     sscanf(str,"%d",&screen);
  66.     for(i=0;i<MAX_SCREENS;i++){
  67.         device=GetScreenDevice(i);
  68.         if(device==NULL)break;
  69.         DisposeWindow(windows[i]);
  70.     }
  71.     return screen;
  72. }
  73.